package cn.yunhe.controller;

import cn.yunhe.model.Role;
import cn.yunhe.model.RoleParams;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zs on 2017/12/4.
 */
@Controller
@RequestMapping("/params")
public class ParamsController {

    @RequestMapping("/commonParamsPojo")
    public ModelAndView commonParams(@RequestParam("role_name") String roleName, String note) {
        System.out.println("roleName=====" + roleName);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }

    @RequestMapping("/findRoles")
    public ModelAndView findRoles(@RequestBody RoleParams roleParams) {
        System.out.println("roleParams===" + roleParams.getRoleName());
        List<Role> roleList = new ArrayList<Role>();
        Role r1 = new Role();
        r1.setId(1L);
        r1.setRoleName("zhangsan");

        Role r2 = new Role();
        r2.setId(2L);
        r2.setRoleName("lisi");

        roleList.add(r1);
        roleList.add(r2);

        ModelAndView mv = new ModelAndView();
        mv.addObject(roleList);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    @RequestMapping("/deleteRoles")
    public ModelAndView deleteRoles(@RequestBody List<Long> idList) {
        ModelAndView mv = new ModelAndView();
        int total = 3;
        mv.addObject("total", total);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    @RequestMapping("/addRoles")
    public ModelAndView addRoles(@RequestBody List<Role> roleList) {
        System.out.println(roleList.get(0).getRoleName());
        ModelAndView mv = new ModelAndView();
        mv.addObject("total", 3);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    @RequestMapping("/commonParamPojo2")
    public ModelAndView commonParamPojo2(String roleName, String note) {
        System.out.println("roleName====" + roleName);
        System.out.println("note====" + note);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }


}
